package com.imonsoft.sqm.dao.sys;

import com.imonsoft.common.httpModel.DataGrid;
import com.imonsoft.common.httpModel.Pager;
import com.imonsoft.sqm.pojo.sys.Function;
import com.imonsoft.sqm.pojo.sys.FunctionExample;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

@SuppressWarnings("deprecation")
@Repository("functionDAO")
public class FunctionDAOImpl extends SqlMapClientDaoSupport implements FunctionDAO {

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public FunctionDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int countFunctionByExample(FunctionExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"ts_function.ibatorgenerated_countByExample", example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int deleteFunctionByExample(FunctionExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"ts_function.ibatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int deleteFunctionByPrimaryKey(Long id) {
		Function key = new Function();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete(
				"ts_function.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public Long insertFunction(Function record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"ts_function.ibatorgenerated_insert", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public Long insertFunctionSelective(Function record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"ts_function.ibatorgenerated_insertSelective", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	@SuppressWarnings("unchecked")
	public List<Function> selectFunctionByExample(FunctionExample example) {
		List<Function> list = getSqlMapClientTemplate().queryForList(
				"ts_function.ibatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public Function selectFunctionByPrimaryKey(Long id) {
		Function key = new Function();
		key.setId(id);
		Function record = (Function) getSqlMapClientTemplate().queryForObject(
				"ts_function.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int updateFunctionByExampleSelective(Function record,
			FunctionExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"ts_function.ibatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int updateFunctionByExample(Function record, FunctionExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"ts_function.ibatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int updateFunctionByPrimaryKeySelective(Function record) {
		int rows = getSqlMapClientTemplate().update(
				"ts_function.ibatorgenerated_updateByPrimaryKeySelective",
				record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	public int updateFunctionByPrimaryKey(Function record) {
		int rows = getSqlMapClientTemplate().update(
				"ts_function.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table ts_function
	 * @ibatorgenerated  Sat Jun 01 16:01:40 CST 2013
	 */
	private static class UpdateByExampleParms extends FunctionExample {
		private Object record;

		public UpdateByExampleParms(Object record, FunctionExample example) {
			super(example);
			this.record = record;
		}

		@SuppressWarnings("unused")
		public Object getRecord() {
			return record;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public DataGrid<Function> getDataGrid(FunctionExample example, Pager pager) {
		if (example == null) {
			example = new FunctionExample();
		}
		int total = countFunctionByExample(example);
		List<Function> rows = getSqlMapClientTemplate().queryForList("ts_function.ibatorgenerated_selectByExample", example, pager.getSkipResults(), pager.getRows());
		DataGrid<Function> dataGrid = new DataGrid<Function>(total, rows);
		return dataGrid;
	}

	@SuppressWarnings("unchecked")
	public List<Function> getFunctionListByUserId(Long userId) {
		if (userId == null) {
			return null;
		}
		List<Function> rows = getSqlMapClientTemplate().queryForList("ts_function.getFunctionListByUserId", userId);
		return rows;
	}
}